import http from "../plugins/http";
import * as utils from "../utils";

/**
 * 公共服务——登录
 */
const login = params => {
  return http.post({
    url: "ggfw/open/oauth/token",
    params
  });
};

/**
 * 公共服务——快速登录
 */
const fastLogin = params => {
  return http.post({
    url: "ggfw/open/oauth/token",
    headers: {
      anonymous: true
    },
    params: {
      grant_type: "password",
      client_id: "ggfwweb",
      client_secret: "neuqggfw",
      username: utils.trim(params.username),
      password: utils.md5(params.password)
    }
  });
};

const thirdLogin = params => {
  return http.post({
    url: "./rest/auth/oauth/token",
    headers: {
      anonymous: true
    },
    params: {
      grant_type: "password",
      // source: "host",

      client_id: "mycd",
      client_secret: "test1111",
      username: params.username,
      password: utils.md5(params.password),
      // client_id: "ggfw",
      // client_secret: "test2222",

      // client_id: params.id,
      // client_secret: params.secret,
      // username: params.code,
      // password: params.state,
      scope: "baseInfo"
    }
  });
};

/**
 * 公共服务——登录（社保卡服务密码）
 */
const loginForSBK = params => {
  return http.post({
    url: "ggfw/open/oauth/token",
    params: {
      grant_type: "password",
      client_id: "ggfwweb",
      client_secret: "neuqggfw",
      source: "sbk",
      mode: "uas",
      username: utils.trim(params.username),
      password: utils.trim(params.password)
    }
  });
};

/**
 * 公共服务——个人信息
 */
const getUser = () => {
  // 公共服务用户
  // return http.get.auth({url: 'ggfw/api/jcxx/user/userinfo'})
  // 社保卡用户
  return http.get({ url: "ggfw/api/jcxx/user/getsbkinfo" });
};

/**
 * 公共服务——代码项——AA10
 */
const getAA10 = () => {
  return http.get({
    url: "ggfw/api/jcxx/code/aa10",
    headers: {
      anonymous: true
    }
  });
};

/**
 * 公共服务——社会保障——社保账户四合一（除工伤）
 */
const getSHBZ = () => {
  return http.get({ url: "ggfw/api/shbz/v3/cover/query" });
};

/**
 * 公共服务——第三方登录
 */
const thirdPartyLogin = (sign, platformName, htmlUrl) => {
  return http.get({
    url: "ggfw/api/jcxx/jump/anonymous/common/check",
    params: {
      sign,
      platformName,
      htmlUrl
    }
  });
};

export {
  login,
  loginForSBK,
  fastLogin,
  thirdLogin,
  thirdPartyLogin,
  getUser,
  getAA10,
  getSHBZ
};
